package com.demo.controller;

import com.demo.dto.InstructorDTO;
import com.demo.dto.InstructorPageQueryDTO;
import com.demo.result.PageResult;
import com.demo.result.Result;
import com.demo.service.InstructorService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin(origins = "http://localhost:8080")
@RequestMapping("/admin/instructor")
public class InstructorController {
    @Autowired
    InstructorService instructorService;

    /**
     * 添加辅导员
     * @param instructorDTO
     * @return
     */
    @PostMapping
    public Result addInstructor(@RequestBody InstructorDTO instructorDTO){
        System.out.println(instructorDTO);
        instructorService.save(instructorDTO);
        return Result.success();
    }

    /**
     * 删除辅导员信息
     * @param instID
     * @return
     */
    @DeleteMapping("/id")
    public Result delete(@RequestParam("instID") String instID){
        instructorService.deleteById(instID);
        return Result.success();
    }

    /**
     * 批量删除
     * @param instIDs
     * @return
     */
    @DeleteMapping
    public Result delete(@RequestBody String[] instIDs){
        System.out.println(instIDs);
        instructorService.delete(instIDs);
        return Result.success();
    }

    /**
     * 分页查询
     * @param instructorPageQueryDTO
     * @return
     */
    @PostMapping("/page")
    public Result<PageResult> page(@RequestBody InstructorPageQueryDTO instructorPageQueryDTO){
        PageResult pageResult=instructorService.pageQuery(instructorPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 修改辅导员信息
     * @param instructorDTO
     * @return
     */
    @PutMapping
    public Result update(@RequestBody InstructorDTO instructorDTO){
        instructorService.update(instructorDTO);
        return Result.success();
    }
}
